﻿namespace WLFramework.Web.Binder.ValueProvider
{
    using System;
    using System.Collections.Generic;
    using System.Collections.Specialized;
    using System.Linq;
    using System.Text;
    using System.Web;
    
    public class CookieValueProvider : NameValueCollectionValueProvider
    {
        public CookieValueProvider()
            : base(ToNameValue(System.Web.HttpContext.Current.Request.Cookies))
        {            
        }

        public CookieValueProvider(HttpCookieCollection collection)
            : base(ToNameValue(collection))
        { 
        }

        public CookieValueProvider(NameValueCollection collection)
            : base(collection)
        { 
        }

        private static NameValueCollection ToNameValue(HttpCookieCollection collection)
        {
            Shield.AssertNotNull(ref collection, "collection");

            NameValueCollection target = new NameValueCollection();

            foreach (string key in collection.AllKeys)
            {
                target.Add(key, collection[key].Value);
            }

            return target;
        }
    }
}
